(0) Obligation:

The Runtime Complexity (innermost) of the given CpxTRS could be proven to be BOUNDS(1, n^3).


The TRS R consists of the following rules:

minus(0, y) → 0
minus(s(x), y) → if(gt(s(x), y), x, y)
if(true, x, y) → s(minus(x, y))
if(false, x, y) → 0
mod(x, 0) → 0
mod(x, s(y)) → if1(lt(x, s(y)), x, s(y))
if1(true, x, y) → x
if1(false, x, y) → mod(minus(x, y), y)
gt(0, y) → false
gt(s(x), 0) → true
gt(s(x), s(y)) → gt(x, y)
lt(x, 0) → false
lt(0, s(x)) → true
lt(s(x), s(y)) → lt(x, y)

Rewrite Strategy: INNERMOST

(1) TrsToWeightedTrsProof (BOTH BOUNDS(ID, ID) transformation)

Transformed TRS to weighted TRS

(2) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, n^3).


The TRS R consists of the following rules:

minus(0, y) → 0 [1]
minus(s(x), y) → if(gt(s(x), y), x, y) [1]
if(true, x, y) → s(minus(x, y)) [1]
if(false, x, y) → 0 [1]
mod(x, 0) → 0 [1]
mod(x, s(y)) → if1(lt(x, s(y)), x, s(y)) [1]
if1(true, x, y) → x [1]
if1(false, x, y) → mod(minus(x, y), y) [1]
gt(0, y) → false [1]
gt(s(x), 0) → true [1]
gt(s(x), s(y)) → gt(x, y) [1]
lt(x, 0) → false [1]
lt(0, s(x)) → true [1]
lt(s(x), s(y)) → lt(x, y) [1]

Rewrite Strategy: INNERMOST

(3) TypeInferenceProof (BOTH BOUNDS(ID, ID) transformation)

Infered types.

(4) Obligation:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

minus(0, y) → 0 [1]
minus(s(x), y) → if(gt(s(x), y), x, y) [1]
if(true, x, y) → s(minus(x, y)) [1]
if(false, x, y) → 0 [1]
mod(x, 0) → 0 [1]
mod(x, s(y)) → if1(lt(x, s(y)), x, s(y)) [1]
if1(true, x, y) → x [1]
if1(false, x, y) → mod(minus(x, y), y) [1]
gt(0, y) → false [1]
gt(s(x), 0) → true [1]
gt(s(x), s(y)) → gt(x, y) [1]
lt(x, 0) → false [1]
lt(0, s(x)) → true [1]
lt(s(x), s(y)) → lt(x, y) [1]

The TRS has the following type information:
minus :: 0:s → 0:s → 0:s
0 :: 0:s
s :: 0:s → 0:s
if :: true:false → 0:s → 0:s → 0:s
gt :: 0:s → 0:s → true:false
true :: true:false
false :: true:false
mod :: 0:s → 0:s → 0:s
if1 :: true:false → 0:s → 0:s → 0:s
lt :: 0:s → 0:s → true:false

Rewrite Strategy: INNERMOST

(5) CompletionProof (UPPER BOUND(ID) transformation)

The TRS is a completely defined constructor system, as every type has a constant constructor and the following rules were added:
none

And the following fresh constants: none

(6) Obligation:

Runtime Complexity Weighted TRS where all functions are completely defined. The underlying TRS is:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

minus(0, y) → 0 [1]
minus(s(x), y) → if(gt(s(x), y), x, y) [1]
if(true, x, y) → s(minus(x, y)) [1]
if(false, x, y) → 0 [1]
mod(x, 0) → 0 [1]
mod(x, s(y)) → if1(lt(x, s(y)), x, s(y)) [1]
if1(true, x, y) → x [1]
if1(false, x, y) → mod(minus(x, y), y) [1]
gt(0, y) → false [1]
gt(s(x), 0) → true [1]
gt(s(x), s(y)) → gt(x, y) [1]
lt(x, 0) → false [1]
lt(0, s(x)) → true [1]
lt(s(x), s(y)) → lt(x, y) [1]

The TRS has the following type information:
minus :: 0:s → 0:s → 0:s
0 :: 0:s
s :: 0:s → 0:s
if :: true:false → 0:s → 0:s → 0:s
gt :: 0:s → 0:s → true:false
true :: true:false
false :: true:false
mod :: 0:s → 0:s → 0:s
if1 :: true:false → 0:s → 0:s → 0:s
lt :: 0:s → 0:s → true:false

Rewrite Strategy: INNERMOST

(7) CpxTypedWeightedTrsToRntsProof (UPPER BOUND(ID) transformation)

Transformed the TRS into an over-approximating RNTS by (improved) Size Abstraction.
The constant constructors are abstracted as follows:

0 => 0
true => 1
false => 0

(8) Obligation:

Complexity RNTS consisting of the following rules:

gt(z, z') -{ 1 }→ gt(x, y) :|: z' = 1 + y, x >= 0, y >= 0, z = 1 + x
gt(z, z') -{ 1 }→ 1 :|: x >= 0, z = 1 + x, z' = 0
gt(z, z') -{ 1 }→ 0 :|: y >= 0, z = 0, z' = y
if(z, z', z'') -{ 1 }→ 0 :|: z' = x, z'' = y, x >= 0, y >= 0, z = 0
if(z, z', z'') -{ 1 }→ 1 + minus(x, y) :|: z' = x, z'' = y, z = 1, x >= 0, y >= 0
if1(z, z', z'') -{ 1 }→ x :|: z' = x, z'' = y, z = 1, x >= 0, y >= 0
if1(z, z', z'') -{ 1 }→ mod(minus(x, y), y) :|: z' = x, z'' = y, x >= 0, y >= 0, z = 0
lt(z, z') -{ 1 }→ lt(x, y) :|: z' = 1 + y, x >= 0, y >= 0, z = 1 + x
lt(z, z') -{ 1 }→ 1 :|: z' = 1 + x, x >= 0, z = 0
lt(z, z') -{ 1 }→ 0 :|: x >= 0, z = x, z' = 0
minus(z, z') -{ 1 }→ if(gt(1 + x, y), x, y) :|: x >= 0, y >= 0, z = 1 + x, z' = y
minus(z, z') -{ 1 }→ 0 :|: y >= 0, z = 0, z' = y
mod(z, z') -{ 1 }→ if1(lt(x, 1 + y), x, 1 + y) :|: z' = 1 + y, x >= 0, y >= 0, z = x
mod(z, z') -{ 1 }→ 0 :|: x >= 0, z = x, z' = 0

Only complete derivations are relevant for the runtime complexity.

(9) CompleteCoflocoProof (EQUIVALENT transformation)

Transformed the RNTS (where only complete derivations are relevant) into cost relations for CoFloCo:

eq(start(V, V1, V5),0,[minus(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V5),0,[if(V, V1, V5, Out)],[V >= 0,V1 >= 0,V5 >= 0]).
eq(start(V, V1, V5),0,[mod(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V5),0,[if1(V, V1, V5, Out)],[V >= 0,V1 >= 0,V5 >= 0]).
eq(start(V, V1, V5),0,[gt(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V5),0,[lt(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(minus(V, V1, Out),1,[],[Out = 0,V2 >= 0,V = 0,V1 = V2]).
eq(minus(V, V1, Out),1,[gt(1 + V3, V4, Ret0),if(Ret0, V3, V4, Ret)],[Out = Ret,V3 >= 0,V4 >= 0,V = 1 + V3,V1 = V4]).
eq(if(V, V1, V5, Out),1,[minus(V6, V7, Ret1)],[Out = 1 + Ret1,V1 = V6,V5 = V7,V = 1,V6 >= 0,V7 >= 0]).
eq(if(V, V1, V5, Out),1,[],[Out = 0,V1 = V8,V5 = V9,V8 >= 0,V9 >= 0,V = 0]).
eq(mod(V, V1, Out),1,[],[Out = 0,V10 >= 0,V = V10,V1 = 0]).
eq(mod(V, V1, Out),1,[lt(V11, 1 + V12, Ret01),if1(Ret01, V11, 1 + V12, Ret2)],[Out = Ret2,V1 = 1 + V12,V11 >= 0,V12 >= 0,V = V11]).
eq(if1(V, V1, V5, Out),1,[],[Out = V13,V1 = V13,V5 = V14,V = 1,V13 >= 0,V14 >= 0]).
eq(if1(V, V1, V5, Out),1,[minus(V15, V16, Ret02),mod(Ret02, V16, Ret3)],[Out = Ret3,V1 = V15,V5 = V16,V15 >= 0,V16 >= 0,V = 0]).
eq(gt(V, V1, Out),1,[],[Out = 0,V17 >= 0,V = 0,V1 = V17]).
eq(gt(V, V1, Out),1,[],[Out = 1,V18 >= 0,V = 1 + V18,V1 = 0]).
eq(gt(V, V1, Out),1,[gt(V19, V20, Ret4)],[Out = Ret4,V1 = 1 + V20,V19 >= 0,V20 >= 0,V = 1 + V19]).
eq(lt(V, V1, Out),1,[],[Out = 0,V21 >= 0,V = V21,V1 = 0]).
eq(lt(V, V1, Out),1,[],[Out = 1,V1 = 1 + V22,V22 >= 0,V = 0]).
eq(lt(V, V1, Out),1,[lt(V23, V24, Ret5)],[Out = Ret5,V1 = 1 + V24,V23 >= 0,V24 >= 0,V = 1 + V23]).
input_output_vars(minus(V,V1,Out),[V,V1],[Out]).
input_output_vars(if(V,V1,V5,Out),[V,V1,V5],[Out]).
input_output_vars(mod(V,V1,Out),[V,V1],[Out]).
input_output_vars(if1(V,V1,V5,Out),[V,V1,V5],[Out]).
input_output_vars(gt(V,V1,Out),[V,V1],[Out]).
input_output_vars(lt(V,V1,Out),[V,V1],[Out]).

CoFloCo proof output:
Preprocessing Cost Relations
=====================================

#### Computed strongly connected components
0. recursive : [gt/3]
1. recursive : [if/4,minus/3]
2. recursive : [lt/3]
3. recursive : [if1/4, (mod)/3]
4. non_recursive : [start/3]

#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into gt/3
1. SCC is partially evaluated into minus/3
2. SCC is partially evaluated into lt/3
3. SCC is partially evaluated into (mod)/3
4. SCC is partially evaluated into start/3

Control-Flow Refinement of Cost Relations
=====================================

### Specialization of cost equations gt/3
* CE 18 is refined into CE [22]
* CE 17 is refined into CE [23]
* CE 16 is refined into CE [24]


### Cost equations --> "Loop" of gt/3
* CEs [23] --> Loop 15
* CEs [24] --> Loop 16
* CEs [22] --> Loop 17

### Ranking functions of CR gt(V,V1,Out)
* RF of phase [17]: [V,V1]

#### Partial ranking functions of CR gt(V,V1,Out)
* Partial RF of phase [17]:
- RF of loop [17:1]:
V
V1


### Specialization of cost equations minus/3
* CE 10 is refined into CE [25]
* CE 12 is refined into CE [26]
* CE 11 is refined into CE [27,28]


### Cost equations --> "Loop" of minus/3
* CEs [28] --> Loop 18
* CEs [27] --> Loop 19
* CEs [25] --> Loop 20
* CEs [26] --> Loop 21

### Ranking functions of CR minus(V,V1,Out)
* RF of phase [18]: [V-1,V-V1]
* RF of phase [19]: [V]

#### Partial ranking functions of CR minus(V,V1,Out)
* Partial RF of phase [18]:
- RF of loop [18:1]:
V-1
V-V1
* Partial RF of phase [19]:
- RF of loop [19:1]:
V


### Specialization of cost equations lt/3
* CE 21 is refined into CE [29]
* CE 19 is refined into CE [30]
* CE 20 is refined into CE [31]


### Cost equations --> "Loop" of lt/3
* CEs [30] --> Loop 22
* CEs [31] --> Loop 23
* CEs [29] --> Loop 24

### Ranking functions of CR lt(V,V1,Out)
* RF of phase [24]: [V,V1]

#### Partial ranking functions of CR lt(V,V1,Out)
* Partial RF of phase [24]:
- RF of loop [24:1]:
V
V1


### Specialization of cost equations (mod)/3
* CE 14 is refined into CE [32,33]
* CE 15 is refined into CE [34]
* CE 13 is refined into CE [35,36]


### Cost equations --> "Loop" of (mod)/3
* CEs [36] --> Loop 25
* CEs [35] --> Loop 26
* CEs [33] --> Loop 27
* CEs [34] --> Loop 28
* CEs [32] --> Loop 29

### Ranking functions of CR mod(V,V1,Out)
* RF of phase [25]: [V-1,V-V1]

#### Partial ranking functions of CR mod(V,V1,Out)
* Partial RF of phase [25]:
- RF of loop [25:1]:
V-1
V-V1


### Specialization of cost equations start/3
* CE 3 is refined into CE [37]
* CE 5 is refined into CE [38,39,40,41]
* CE 2 is refined into CE [42,43,44,45,46,47,48,49]
* CE 4 is refined into CE [50]
* CE 6 is refined into CE [51,52,53,54]
* CE 7 is refined into CE [55,56,57,58,59,60]
* CE 8 is refined into CE [61,62,63,64]
* CE 9 is refined into CE [65,66,67,68]


### Cost equations --> "Loop" of start/3
* CEs [58] --> Loop 30
* CEs [54,57,60,64,67] --> Loop 31
* CEs [39,53,59,63,68] --> Loop 32
* CEs [37,38,40,41] --> Loop 33
* CEs [46] --> Loop 34
* CEs [44] --> Loop 35
* CEs [42,52,56,62,66] --> Loop 36
* CEs [43,45,47,48,49,50,51,55,61,65] --> Loop 37

### Ranking functions of CR start(V,V1,V5)

#### Partial ranking functions of CR start(V,V1,V5)


Computing Bounds
=====================================

#### Cost of chains of gt(V,V1,Out):
* Chain [[17],16]: 1*it(17)+1
Such that:it(17) =< V

with precondition: [Out=0,V>=1,V1>=V]

* Chain [[17],15]: 1*it(17)+1
Such that:it(17) =< V1

with precondition: [Out=1,V1>=1,V>=V1+1]

* Chain [16]: 1
with precondition: [V=0,Out=0,V1>=0]

* Chain [15]: 1
with precondition: [V1=0,Out=1,V>=1]


#### Cost of chains of minus(V,V1,Out):
* Chain [[19],21]: 3*it(19)+1
Such that:it(19) =< Out

with precondition: [V1=0,V=Out,V>=1]

* Chain [[18],20]: 3*it(18)+1*s(1)+1*s(4)+3
Such that:it(18) =< Out
aux(2) =< V-Out
s(1) =< aux(2)
s(4) =< it(18)*aux(2)

with precondition: [V=Out+V1,V1>=1,V>=V1+1]

* Chain [21]: 1
with precondition: [V=0,Out=0,V1>=0]

* Chain [20]: 1*s(1)+3
Such that:s(1) =< V

with precondition: [Out=0,V>=1,V1>=V]


#### Cost of chains of lt(V,V1,Out):
* Chain [[24],23]: 1*it(24)+1
Such that:it(24) =< V

with precondition: [Out=1,V>=1,V1>=V+1]

* Chain [[24],22]: 1*it(24)+1
Such that:it(24) =< V1

with precondition: [Out=0,V1>=1,V>=V1]

* Chain [23]: 1
with precondition: [V=0,Out=1,V1>=1]

* Chain [22]: 1
with precondition: [V1=0,Out=0,V>=0]


#### Cost of chains of mod(V,V1,Out):
* Chain [[25],27]: 6*it(25)+1*s(5)+2*s(15)+3*s(16)+1*s(17)+3
Such that:aux(5) =< V
aux(6) =< V-V1
s(12) =< V1
s(5) =< Out
aux(8) =< V-Out
it(25) =< aux(8)
it(25) =< aux(5)
s(18) =< aux(5)
it(25) =< aux(6)
s(18) =< aux(8)
s(16) =< it(25)*aux(6)
s(15) =< s(18)
s(17) =< s(16)*s(12)

with precondition: [Out>=1,V1>=Out+1,V>=Out+V1]

* Chain [[25],26,29]: 6*it(25)+2*s(15)+3*s(16)+1*s(17)+2*s(19)+9
Such that:aux(5) =< V
aux(10) =< V-V1
aux(11) =< V1
it(25) =< aux(10)
s(19) =< aux(11)
it(25) =< aux(5)
s(18) =< aux(5)
s(18) =< aux(10)
s(16) =< it(25)*aux(10)
s(15) =< s(18)
s(17) =< s(16)*aux(11)

with precondition: [Out=0,V1>=1,V>=2*V1]

* Chain [29]: 3
with precondition: [V=0,Out=0,V1>=1]

* Chain [28]: 1
with precondition: [V1=0,Out=0,V>=0]

* Chain [27]: 1*s(5)+3
Such that:s(5) =< V

with precondition: [V=Out,V>=1,V1>=V+1]

* Chain [26,29]: 2*s(19)+9
Such that:aux(9) =< V
s(19) =< aux(9)

with precondition: [Out=0,V=V1,V>=1]


#### Cost of chains of start(V,V1,V5):
* Chain [37]: 1*s(21)+13*s(22)+5*s(24)+3*s(25)+12*s(29)+6*s(32)+2*s(33)+2*s(34)+13
Such that:s(21) =< V1
aux(17) =< V1-2*V5
aux(18) =< V1-V5
aux(19) =< V5
s(22) =< aux(18)
s(29) =< aux(17)
s(24) =< aux(19)
s(29) =< aux(18)
s(31) =< aux(18)
s(31) =< aux(17)
s(32) =< s(29)*aux(17)
s(33) =< s(31)
s(34) =< s(32)*aux(19)
s(25) =< s(22)*aux(19)

with precondition: [V=0,V1>=0]

* Chain [36]: 3*s(54)+5
Such that:s(54) =< V

with precondition: [V1=0,V>=0]

* Chain [35]: 3*s(55)+3
Such that:s(55) =< V1

with precondition: [V=0,V5=0,V1>=1]

* Chain [34]: 6*s(56)+1*s(59)+13
Such that:aux(20) =< V5
s(56) =< aux(20)
s(59) =< s(56)*aux(20)

with precondition: [V=0,V1=2*V5,V1>=2]

* Chain [33]: 1*s(62)+3*s(63)+1*s(65)+1*s(66)+4
Such that:s(62) =< V1
s(63) =< V1-V5
s(64) =< V5
s(65) =< s(64)
s(66) =< s(63)*s(64)

with precondition: [V=1,V1>=0,V5>=0]

* Chain [32]: 3*s(67)+4*s(68)+3
Such that:s(67) =< V1
aux(21) =< V
s(68) =< aux(21)

with precondition: [V>=1,V1>=V]

* Chain [31]: 3*s(72)+5*s(74)+1*s(75)+3*s(81)+6*s(83)+3*s(85)+1*s(87)+9
Such that:aux(22) =< V
aux(23) =< V-V1
aux(24) =< V1
s(72) =< aux(23)
s(74) =< aux(24)
s(75) =< s(72)*aux(24)
s(81) =< aux(22)
s(83) =< aux(22)
s(83) =< aux(23)
s(85) =< s(83)*aux(23)
s(87) =< s(85)*aux(24)

with precondition: [V1>=1,V>=V1]

* Chain [30]: 6*s(93)+2*s(94)+3*s(96)+2*s(97)+1*s(98)+9
Such that:s(90) =< V
s(91) =< V-V1
s(92) =< V1
s(93) =< s(91)
s(94) =< s(92)
s(93) =< s(90)
s(95) =< s(90)
s(95) =< s(91)
s(96) =< s(93)*s(91)
s(97) =< s(95)
s(98) =< s(96)*s(92)

with precondition: [V1>=1,V>=2*V1]


Closed-form bounds of start(V,V1,V5):
-------------------------------------
* Chain [37] with precondition: [V=0,V1>=0]
- Upper bound: V1+13+nat(V5)*5+nat(V5)*3*nat(V1-V5)+nat(V5)*2*nat(V1-2*V5)*nat(V1-2*V5)+nat(V1-V5)*15+nat(V1-2*V5)*12+nat(V1-2*V5)*6*nat(V1-2*V5)
- Complexity: n^3
* Chain [36] with precondition: [V1=0,V>=0]
- Upper bound: 3*V+5
- Complexity: n
* Chain [35] with precondition: [V=0,V5=0,V1>=1]
- Upper bound: 3*V1+3
- Complexity: n
* Chain [34] with precondition: [V=0,V1=2*V5,V1>=2]
- Upper bound: 6*V5+13+V5*V5
- Complexity: n^2
* Chain [33] with precondition: [V=1,V1>=0,V5>=0]
- Upper bound: V1+V5+4+nat(V1-V5)*V5+nat(V1-V5)*3
- Complexity: n^2
* Chain [32] with precondition: [V>=1,V1>=V]
- Upper bound: 4*V+3*V1+3
- Complexity: n
* Chain [31] with precondition: [V1>=1,V>=V1]
- Upper bound: 3*V-3*V1+ (9*V+5*V1+9+ (V-V1)*V1+ (V-V1)*V1*V)+ (3*V-3*V1)*V
- Complexity: n^3
* Chain [30] with precondition: [V1>=1,V>=2*V1]
- Upper bound: 6*V-6*V1+ (2*V+2*V1+9+ (V-V1)* ((V-V1)*V1))+ (3*V-3*V1)* (V-V1)
- Complexity: n^3

### Maximum cost of start(V,V1,V5): max([max([3*V,nat(V5)*6+8+nat(V5)*nat(V5)])+2,max([max([V1,2*V+max([nat(V-V1)*V1*nat(V-V1)+6+nat(V-V1)*6+nat(V-V1)*3*nat(V-V1),5*V+2*V1+6+nat(V-V1)*V1+nat(V-V1)*V1*V+nat(V-V1)*3+nat(V-V1)*3*V+ (2*V+V1)])])+V1,nat(V5)*4+9+nat(V5)*2*nat(V1-V5)+nat(V5)*2*nat(V1-2*V5)*nat(V1-2*V5)+nat(V1-V5)*12+nat(V1-2*V5)*12+nat(V1-2*V5)*6*nat(V1-2*V5)+ (nat(V5)+1+nat(V1-V5)*nat(V5)+nat(V1-V5)*3)])+V1])+3
Asymptotic class: n^3
* Total analysis performed in 458 ms.

(10) BOUNDS(1, n^3)